//
//  PhotoStyleChooseView.m
//  MoodDiary
//
//  Created by TanJian on 2022/1/22.
//

#import "PhotoStyleChooseView.h"

@interface PhotoStyleChooseView()

@property (nonatomic,assign) PageType pageType;

@end

@implementation PhotoStyleChooseView

-(instancetype)initWithFrame:(CGRect)frame type:(PageType)pageType{
    
    if (self = [super initWithFrame:frame]) {
        _pageType = pageType;
        [self initUI];
    }
    return self;
}

-(void)initUI{
    
    UIView *bgView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.width, self.height)];
    [self addSubview:bgView];
    bgView.userInteractionEnabled = YES;
    bgView.backgroundColor = [UIColor blackColor];
    bgView.alpha = 0.6;
    UITapGestureRecognizer *bgTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(closeView)];
    [bgView addGestureRecognizer:bgTap];
    
    
    UIView *whiteView = [[UIView alloc] initWithFrame:CGRectMake(0, DEF_SCREEN_HEIGHT-DEF_Tabbar_SafeBottomMargin-255, self.width, 255+DEF_Tabbar_SafeBottomMargin+20)];
    whiteView.backgroundColor = [UIColor whiteColor];
    whiteView.layer.cornerRadius = 20;
    whiteView.layer.masksToBounds = YES;
    [self addSubview:whiteView];
    
    
    UILabel *titleLabel = [UILabel new];
    titleLabel.textColor = [UIColor blackColor];
    titleLabel.textAlignment = NSTextAlignmentCenter;
    titleLabel.font = [UIFont boldSystemFontOfSize:18];
    titleLabel.text = @"请选上传图片的方式";
    [titleLabel sizeToFit];
    titleLabel.frame = CGRectMake(0, 30, whiteView.width, titleLabel.height);
    [whiteView addSubview:titleLabel];
    
    
    UIButton *closeBtn = [[UIButton alloc] initWithFrame:CGRectMake(self.width-38-20, 10, 38, 38)];
    [closeBtn setImage:[UIImage imageNamed:@"photo_close"] forState:UIControlStateNormal];
    [closeBtn addTarget:self action:@selector(closeView) forControlEvents:UIControlEventTouchUpInside];
    [whiteView addSubview:closeBtn];
    
    
    UIButton *albumBtn = [[UIButton alloc] initWithFrame:CGRectMake(38, 94, self.width-38*2, 50)];
    albumBtn.layer.cornerRadius = 10;
    albumBtn.clipsToBounds = YES;
    albumBtn.layer.borderWidth = 1;
    albumBtn.layer.borderColor = [UIColor lightGrayColor].CGColor;
    [albumBtn addTarget:self action:@selector(albumBtnAction) forControlEvents:UIControlEventTouchUpInside];
    [whiteView addSubview:albumBtn];
    
    UIImageView *albumImg = [[UIImageView alloc] initWithFrame:CGRectMake(self.width*0.5-30, albumBtn.y+16, 18, 18)];
    albumImg.image = [UIImage imageNamed:@"photo_photo"];
    [whiteView addSubview:albumImg];
    
    UILabel *albumLabel = [[UILabel alloc] initWithFrame:CGRectMake(self.width*0.5, albumBtn.y+14, 36, 22)];
    albumLabel.text = @"相册";
    albumLabel.textColor = [UIColor blackColor];
    albumLabel.font = [UIFont systemFontOfSize:16];
    [whiteView addSubview:albumLabel];
    
    
    
    UIButton *cameraBtn = [[UIButton alloc] initWithFrame:CGRectMake(38, albumBtn.bottom+20, self.width-38*2, 50)];
    cameraBtn.layer.cornerRadius = 10;
    cameraBtn.clipsToBounds = YES;
    cameraBtn.layer.borderWidth = 1;
    cameraBtn.layer.borderColor = [UIColor lightGrayColor].CGColor;
    [cameraBtn addTarget:self action:@selector(cameraBtnAction) forControlEvents:UIControlEventTouchUpInside];
    [whiteView addSubview:cameraBtn];
    
    UIImageView *cameraImg = [[UIImageView alloc] initWithFrame:CGRectMake(self.width*0.5-30, cameraBtn.y+16, 18, 18)];
    cameraImg.image = [UIImage imageNamed:@"photo_camera"];
    [whiteView addSubview:cameraImg];
    
    UILabel *cameraLabel = [[UILabel alloc] initWithFrame:CGRectMake(self.width*0.5, cameraBtn.y+14, 36, 22)];
    cameraLabel.text = @"相机";
    cameraLabel.textColor = [UIColor blackColor];
    cameraLabel.font = [UIFont systemFontOfSize:16];
    [whiteView addSubview:cameraLabel];
    
    if (self.pageType == PageTypeEdit) {
        
        titleLabel.text = @"请选择您要进行的操作";
        albumImg.image = [UIImage imageNamed:@"edit_edit"];
        albumLabel.text = @"编辑";
        cameraImg.image = [UIImage imageNamed:@"edit_delete"];
        cameraLabel.text = @"删除";
        
    }
    
}


-(void)closeView{
    
    [self removeFromSuperview];
}

-(void)albumBtnAction{
    
    if (self.albumBlock) {
        self.albumBlock();
    }
    [self closeView];
}

-(void)cameraBtnAction{
    
    if (self.cameraBlock) {
        self.cameraBlock();
    }
    [self closeView];
}

@end
